# This code is based on Darwin's theory of 'survival of the fittest'.

#
# These variables keep track of our hunts and not-hunts in order to
# manipulate our reputation at a later stage.
#
h=0
s=0

def hunt_choices(round_number, current_food, current_reputation, m,  player_reputations):
    global h, s
    hunt_decisions=[]
#
# In first turn, we build reputation of 100% assuming:
# On average, players would want to build reputation, but at the same time,
# they will be causious. So, we assume about half of the players will hunt.
# Good reputation will help us in further turns, so that players would want to hunt with us.
# In second turn, we can recover our losses by having reputation of 100% & yet
# not hunting with appropriate number of players.
#
# This trick is valid only at the beginning of the game, because in the first turn,
# reputations are not known.
#
    if round_number==1:
        for i in range(len(player_reputations)):
            hunt_decisions.append('h')
            h+=1
        return hunt_decisions
#
# If less than 3 players remaining, we don't hunt with anyone. Due to small size of rounds
# in the end game, this won't have any effect on our reputation.
#
    if len(player_reputations)<=2:
        for i in range(len(player_reputations)):
            hunt_decisions.append('s')
            s+=1
        return hunt_decisions
#
# For all other rounds, we arrange all players in ascending order of their reputation.
# Using 'survival of the fittest' strategy:
# In order to increase food units, we need to not hunt in some turns.
# In order to increase our reputation, we need to hunt.
# So, those at the extreme ends of our sorted list would be most vulnerable to getting out.
# We assume that the game (like nature) selects its remaining players such that
# those near the centre of our sorted list are most likely to survive.
# So, we consciously build our reputation to equal that of the player in the mid-point
# of the sorted list.
# Thus, we decide how many times to hunt in this game.
#
    l=player_reputations[:]
    l.sort()
    required_h=int((h+len(l)+s)*l[int(len(l)/2)]-h)+1
    if required_h<=0:
        for i in range(len(player_reputations)):
            hunt_decisions.append('s')
            s+=1
        return hunt_decisions
    elif required_h>=len(l):
        for i in range(len(player_reputations)):
            hunt_decisions.append('h')
            h+=1
        return hunt_decisions
#
# We hunt with the pre-decided number of players in the end of our sorted list
# because they have the highest reputations.
# Thus we try to minimize being betrayed by other players.
#
    for i in range(len(player_reputations)):
        hunt_decisions.append('d')
    for i in range(len(l)-required_h):
        j=player_reputations.index(l[i])
        while hunt_decisions[j]!='d':
            j=player_reputations.index(l[i],j+1)
        hunt_decisions[j]='s'
        s+=1
    for i in range(len(player_reputations)):
        if hunt_decisions[i]=='d':
            hunt_decisions[i]='h'
            h+=1
    return hunt_decisions

def hunt_outcomes(food_earnings):
    pass

def round_end(award, m, number_hunters):
    pass
